perm filename TESTA.SAI[1,JMC] blob
sn#005230 filedate 1969-12-11 generic text, type T, neo UTF8
00050 COMMENT
00100 "PROGRAM TO FIND INTEGERS EXPRESSIBLE AS SUMS OF CUBES
00200 IN TWO DIFFERENT WAYS AND TO LEARN TO USE SAIL";
00300
00400 BEGIN INTEGER n, lim;
00450 COMMENT
00500 "Ask for n, the number up to which cubes are to be taken
00600 and for lim, the size of array to be used for storing
00700 the numbers found.";
00800 outstr("n = "); n ← cvd(inchwl);
00900 outstr("lim = "); lim ← cvd(inchwl);
01400 BEGIN INTEGER ARRAY a[1:lim],b[1:lim],c[1:lim],d[1:lim];
01500 INTEGER m,i,j,k,l,x,w; LABEL r; BOOLEAN p;
01600 integer procedure gcd(integer i, j);
01610 begin integer t; label a;
01620 if i>j then i ↔ j;
01630 a:
01640 if i=0 then return(j);
01650 t←j mod i; j←i; i←t;
01660 go to a end;
01700 m ← 0;
01800 FOR i←1 STEP 1 UNTIL n DO
01900 FOR j←1 STEP 1 UNTIL i DO
02000 FOR k←i+1 STEP 1 UNTIL n DO
02050 begin w ← i↑3+j↑3-k↑3;
02100 for l←j-1 step -1 until 1 do begin x←w-l↑3;
02200 if x=0 and gcd(i,gcd(j,gcd(k,l))) = 1 then
02300 BEGIN m←m+1;a[m] ← i; b[m] ← j; c[m] ← k; d[m] ← l END;
02400 if x>0 then done end end;
02500 r:
02600 p ← FALSE;
02700 FOR i←1 STEP 1 UNTIL m-1 DO
02800 IF a[i]↑3+b[i]↑3 > a[i+1]↑3+b[i+1]↑3 THEN
02900 BEGIN a[i] ↔ a[i+1]; b[i] ↔ b[i+1]; c[i] ↔ c[i+1];
03000 d[i] ↔ d[i+1]; p ← TRUE END;
03100 IF p THEN GO TO r;
03200
03250 COMMENT
03300 "Print the pairs found.";
03400 FOR i←1 STEP 1 UNTIL m DO
03500 OUTSTR(CVS(a[i]↑3+b[i]↑3)&" = "&CVS(a[i])&
03600 "↑3+ "&CVS(b[i])&"↑3 = "&CVS(c[i])&"↑3 + "&
03700 CVS(d[i])&"↑3
03800 ")
03900 END
04000 END;